// Copyright 2012 Square, Inc.

package com.squareup.timessquare;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/** Describes the state of a particular date cell in a {@link MonthView}. */
class MonthCellDescriptor {
  public enum RangeState {
    NONE, FIRST, MIDDLE, LAST
  }

  private final Date date;
  private final int value;
  private final String valueCN;
  private final boolean isCurrentMonth;
  private boolean isSelected;
  private final boolean isToday;
  private final boolean isTomorrow;
  private final boolean isDayAfterTomorrow;
  private final boolean isSelectable;
  private boolean isHighlighted;
  private boolean isHoliDays;
  private RangeState rangeState;

  MonthCellDescriptor(Date date, boolean currentMonth, boolean selectable, boolean selected,
      boolean today,boolean tomorrow,boolean dayAfterTomorrow,String valueCN, boolean highlighted, int value, RangeState rangeState) {
    this.date = date;
    isCurrentMonth = currentMonth;
    isSelectable = selectable;
    isHighlighted = highlighted;
    isSelected = selected;
    isToday = today;
    isTomorrow=tomorrow;
    isDayAfterTomorrow=dayAfterTomorrow;
    this.valueCN=valueCN;
    this.value = value;
    this.rangeState = rangeState;
  }

  public Date getDate() {
    return date;
  }

  public boolean isCurrentMonth() {
    return isCurrentMonth;
  }

  public boolean isSelectable() {
    return isSelectable;
  }

  public boolean isSelected() {
    return isSelected;
  }
  public boolean isHoliDays() {
	return (valueCN != null && !"".equals(valueCN));
}

  public void setSelected(boolean selected) {
    isSelected = selected;
  }

  boolean isHighlighted() {
    return isHighlighted;
  }

  void setHighlighted(boolean highlighted) {
    isHighlighted = highlighted;
  }

  public boolean isToday() {
    return isToday;
  }
  public boolean isTomorrow() {
	return isTomorrow;
  }
  public boolean isDayAfterTomorrow() {
	return isDayAfterTomorrow;
  }
  public RangeState getRangeState() {
    return rangeState;
  }

  public void setRangeState(RangeState rangeState) {
    this.rangeState = rangeState;
  }

  public int getValue() {
    return value;
  }
  
  public String getValueCN(){
	  String s="";
	  if (isToday) {
		s="今天";
	}else if (isTomorrow) {
		s="明天";
	}else if (isDayAfterTomorrow) {
		s="后天";
	}else {
		s= valueCN;
		 if("".equals(s))s=Integer.toString(value);
	}
	 String key= getSimpleFormat("yyyMMdd").format(date);
	if (CalendarPickerView.getPriceMap()!=null && CalendarPickerView.getPriceMap().containsKey(key)) {
		s = s+"\n"+CalendarPickerView.getPriceMap().get(key);
	} 
	  return s;
  }
  private SimpleDateFormat getSimpleFormat(String pattern) {
		 return new SimpleDateFormat(pattern,Locale.CHINA);
  }
  @Override public String toString() {
    return "MonthCellDescriptor{"
        + "date="
        + date
        + ", value="
        + value
        + ", isCurrentMonth="
        + isCurrentMonth
        + ", isSelected="
        + isSelected
        + ", isToday="
        + isToday
        + ", isSelectable="
        + isSelectable
        + ", isHighlighted="
        + isHighlighted
        + ", rangeState="
        + rangeState
        + '}';
  }
}
